<template>
	<!-- 推荐 -->
	<view class="goods">
		<view class="acea-row row-between goods-top">
			<view class="acea-row row-middle tabs">
				<view :class="['tab',goodsTabOn==index?'tab-on':'']" v-for="(item,index) in goodsTab" :key="index"
					@click="goodsTabOn=index;">{{item}}</view>
			</view>
	<!-- 		<view class="shop-btn">
				金币商城
			</view> -->
		</view>
		<view class="acea-row row-between goods-list">
			<view class="item" v-for="(item,index) in nearbyList" :key="index" @click="goDetil('/pages/details/merchantService/merchantService?id='+item.id)">
				<view class="img">
					<image :src="item.image?item.image.split(',')[0]:''" mode=""></image>
					<!-- <video :src="item.image[0].src" mode="" v-if="item.image[0].type == 'video'"></video> -->
				</view>
				<view class="info">
					<view class="title">
						{{ item.title }}
					</view>
					<!-- <view class="acea-row type-list">
						<view class="type">
							7年老店
						</view>
						<view class="type">
							7年老店
						</view>
						<view class="type">
							7年老店
						</view>
					</view> -->
					<view class="acea-row merit-list">
						<view class="merit">
							商业街店铺
						</view>
						<view class="merit">
							商业街店铺
						</view>
					</view>
					<view class="acea-row row-middle row-between price-info">
						<view class="price">
							<text>{{ item.price }}</text>元/月
						</view>
						<view class="wants">
							{{item.view || 0}}人想要
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class='loadingicon acea-row row-center row-middle'>
			<text class='loading iconfont icon-jiazai' :hidden='loading'></text>{{loadTitle}}
		</view>
	</view>
</template>

<script>
	import {
		getMerchantListApi,
		getService,
		getServiceList
	} from '@/api/api.js'
	import {
		getLocation
	} from '@/filters/commFilter.js'
	export default {
		data() {
			return {
				goodsTabOn: 0,
				goodsList: [],
				goodsTab: ['推荐', '附近', '最新'],
				limit: 8,
				page: 1,
				nearbyList: [],
				nearPage:1,
				loading: true,
				loadTitle: '我也是有底线的',
			}
		},
		created() {
			this.getNearbyList()
		},
		watch:{
			goodsTabOn(newVal){
				console.log(newVal)
				this.nearPage = 1;
				this.getNearbyList();
			}
		},
		methods:{
			goDetil(url){
				uni.navigateTo({
					url
				})
			},
			async getNearbyList() {
				let parmas = {
					limit: 8,
					page: this.nearPage,
					city: this.$city
				}
				if (this.goodsTabOn == 1) {
					parmas = {
						...parmas,
						...this.$location
					}
				}
				if(this.nearPage == 1){
					this.nearbyList=[]
				}
				
				try {
					let {
						data
					} = this.goodsTabOn==2?await getServiceList(parmas):await getService(parmas);
					let d = [...this.nearbyList, ...data.list];
					this.nearbyList = d.filter(item => item.id != this.curId && item.id!=this.id)
					console.log('jigweidu=', data)
					this.totalNearPage = data.totalPage;
					this.loading = true;
					if (this.nearPage == data.totalPage && this.nearbyList.length > 0) this.loadTitle = '我也是有底线的'
					else if (this.nearPage < data.totalPage && this.nearbyList.length > 0) this.loadTitle = '加载更多'
					else this.loadTitle = '暂无数据'
				} catch (e) {
					//TODO handle the exception
				}
			},
		},
		onReachBottom() {
			this.nearPage++;
			this.getNearbyList()
		}
	}
</script>

<style lang="scss">
	// 推荐物品
	.goods {
		border-radius: 10rpx 10rpx 0 0;
		margin: 0 26rpx 26rpx;
		padding: 36rpx 0;

		.goods-top {
			.tabs {
				.tab {
					font-size: 32rpx;
					font-weight: 400;
					color: rgba(128, 128, 128, 1);
					margin-right: 24rpx;
				}

				.tab-on {
					font-weight: 700;
					color: rgba(0, 0, 0, 1);
				}
			}

			.shop-btn {
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(238, 33, 45, 1);
				padding: 4rpx 24rpx;
				border-radius: 30rpx;
				border: 1px solid rgba(238, 33, 45, 1);
			}
		}

		.goods-list {
			padding: 30rpx 0;

			.item {
				width: 48%;
				border-radius: 20rpx;
				background: rgba(255, 255, 255, 1);

				.img {
					width: 100%;
					height: 288rpx;
					border-radius: 20rpx 20rpx 0 0;
					background: #ff0000;

					image {
						width: 100%;
						height: 100%;
						border-radius: 20rpx 20rpx 0 0;
					}
				}

				.info {
					padding: 18rpx;

					.title {
						font-size: 28rpx;
						font-weight: 400;
						line-height: 40rpx;
						color: rgba(0, 0, 0, 1);
					}

					.type-list {
						padding: 12rpx 0;
					}

					.type {
						font-size: 24rpx;
						font-weight: 400;
						color: rgba(238, 33, 45, 1);
						padding: 0 12rpx;
						height: 36rpx;
						line-height: 36rpx;
						text-align: center;
						border-radius: 4rpx;
						background: rgba(255, 232, 234, 1);
						letter-spacing: 0.4rpx;
						margin-left: 14rpx;
						margin-bottom: 10rpx;
						white-space: nowrap;
					}

					.merit-list {
						padding: 0 0 12rpx;

						.merit {
							font-size: 22rpx;
							font-weight: 400;
							color: rgba(82, 104, 139, 1);
							padding: 0 6rpx;
							height: 36rpx;
							line-height: 36rpx;
							text-align: center;
							border-radius: 4rpx;
							background: rgba(248, 249, 253, 1);
							letter-spacing: 0.4rpx;
							margin-left: 14rpx;
							margin-bottom: 10rpx;
							white-space: nowrap;
						}
					}

					.price-info {
						.price {
							font-size: 24rpx;
							font-weight: 400;
							color: rgba(238, 33, 45, 1);

							text {
								font-size: 36rpx;
								font-weight: 700;
							}
						}

						.wants {
							font-size: 24rpx;
							font-weight: 400;
							color: rgba(166, 166, 166, 1);
						}
					}
				}
			}
		}
	}
</style>